package com.bjpn.settings.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bjpn.settings.bean.User;
import com.bjpn.settings.mapper.UserMapper;
import com.bjpn.settings.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjpn.util.DateToString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzy
 * @since 2022-09-06
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserByCodeAndPwd(String loginCode, String loginPwd) {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.eq("login_code", loginCode).eq("login_pwd", loginPwd);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public int updatePwdById(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public List<User> getAllUserAvailable() {
        String currentTime = DateToString.currentTimeToString();
        QueryWrapper<User> wrapper = Wrappers.query();
        // 未冻结 且 不过期
        wrapper.eq("user_lock_state", 1).gt("user_expire_time", currentTime);
        return userMapper.selectList(wrapper);
    }


}
